$(document).ready(function() {
    // set up the news accordion on the lower page
    $("#deaccordian").accordion({
        header: "h4" ,
        event: "mouseover",
        icons: false,
        autoHeight: false,
        navigation: true
    });
    $("li a:contains(Admin)").addClass('current');
    $("table#boardCompare").hide();
    $("div.detail").hide();
    $("select#category").change(get_complaints);
    $("div#ajaxload").hide();
    //  $("p.gear a").mouseover(function(){alert($(this).html());});
    $("#mainContent  input:submit").button();
   
});
function show_table()
{
    $("#boardCompare tbody tr:even").addClass("even");
    $("#boardCompare tbody tr:odd").addClass("odd");
    $("#boardCompare tbody tr").click(highlight);
    $("div#ajaxload").hide();
    $("table#boardCompare").fadeIn('slow');
}
function get_complaints(){
   
    var category = $("select#category option:selected").text();

    if(category!="- Select One -"){
        $("div.detail").hide();
        $("table#boardCompare").hide();
        $("div#ajaxload").show();
        //  alert(category);
        data="category="+category+"&status=Recent";
        $.ajax({
            type: 'POST',
            url: base_url() + 'de/get_complaints_ajax',
            data: data,
            datatype: "json",
            success : function (result) {
                var data=$.parseJSON(result);
                var html="";
                for(i=0;i<data.length;i++)
                {
                    html+="<tr>";
                    html+= "<td>"+data[i].appid+"</td>";
                    html+= "<td>"+data[i].applydate+"</td>";
                    html+= "<td>"+data[i].title+"</td>";
                    html+= "</tr>";
                }
                // alert(html);
                $("table#boardCompare tbody").html(html);
                show_table();
            }
        });
    }

}
function highlight(evt)
{
    $("div.detail").hide();
    $("div#ajaxload").show();
    $("#boardCompare tbody tr").removeClass("clickrow");
    $(this).addClass("clickrow");
    var id=this.cells[0].innerHTML;
    var title=this.cells[2].innerHTML;
    //  alert(title+id);
    id="id="+id+"&title="+title;
    $.ajax({
        type: 'POST',
        url: base_url() + 'de/complain_detail_ajax',
        data: id,
        datatype: "json",
        success : function (result) {
            $("div#ajaxload").hide();
            var data=$.parseJSON(result);
            var html="Application ID: "+data.appid+"<br/><br/>"+
            "First Name: "+data.FirstName+"<br/><br/>"+
            "Last Name: "+data.LastName+"<br/><br/>"+
            "Phone Number: "+data.phoneno+"<br/><br/>"+
            "Problem Since: "+data.since+"<br/>";
            if(title=='other')
                html+= "<br/>"+"Description: "+data.description+"<br/>";
            $("div.detail div:first").html(html);
            var hidden='<input type="hidden" name="id" value='+data.appid+" />";
            $("div.process form").prepend(hidden);
            $("div.detail").slideDown("slow");

        }
    });
}

